<?php

namespace app\api\controller;

class Base extends Api
{
    public $user_id = 0;
    public $user_info = [];
    public function _initialize()
    {
        session('user_id',1);
        if (!session('user_id')) {
            header('location:'.url('Wx/user'));
            exit();
        }
        $this->user_id = session('user_id');
        $info = Db('member')->where(['id'=>session('user_id'),'status'=>0])->find();
        if(!$info){
            session('user_id',null);
            header('location:'.url('api/Wx/index'));
            exit();
        }
        $this->user_info = $info;
//        $config = cache('db_config_data');
//        //$config = null;
//        if(!$config){
//            $config = load_config();
//            cache('db_config_data',$config);
//        }
//
//        config($config);

    }
    //获取图片地址
    public function array_image_add_domain($array, $params='')
    {
        foreach ($array as $key => $value) {
            if (empty($params) && !empty($value)) {
                $array[$key] = cdnurl($value, true);
            } elseif (isset($value[$params])) {
                $array[$key][$params] = cdnurl($value[$params], true);
            }
        }
        return $array;
    }

    public function array_time_change($array, $params='', $style='Y-m-d H:i:s')
    {
        foreach ($array as $key => $value) {
            if (isset($value[$params])) {
                $array[$key][$params] = date($style, $value[$params]);
            }
        }
        return $array;
    }
}